﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using Algobox.Structure.Finance.Prices;

namespace Algobox.Objects.Finance.Assets.Stock
{
    public class StockSecurity : IStock
    {
        public StockSecurity(string symbol, Markets.MarketMIC market)
        {
            Symbol = symbol;
            Market = market;
            Listings = new ConcurrentDictionary<Exchanges.ExchangeMIC, StockListing>();
            Prices = new StockWatch(this);
        }

        public string Symbol { get; private set; }
        public Markets.MarketMIC Market { get; set; }
        public string ISIN { get; set; }
        public Currencies.Currency Currency { get; set; }
        public string Bloomberg { get; set; }
        public string Reuters { get; set; }
        public string Index { get; set; }
        public string Sector { get; set; }
        public string IndustryGroup { get; set; }
        public string Industry { get; set; }
        public ConcurrentDictionary<Exchanges.ExchangeMIC, StockListing> Listings { get; private set; }

        public StockWatch Prices { get; set; }

        public override string ToString()
        {
            return Market + ":" + Symbol;
        }

        Phases.Phase _phase;
        Object _phaseLock = new object();
        public Phases.Phase Phase
        {
            get { return _phase; }
            set
            {
                lock (_phaseLock)
                {
                    if (_phase != value)
                    {
                        _phasePrevious = _phase;
                        _phase = value;
                    }
                }
            }
        }

        Phases.Phase _phasePrevious;
        public Phases.Phase PhasePrevious { get { return _phasePrevious; } }

    }
}
